package com.lzyyj.gmis.base.webui.action;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.lzyyj.gmis.base.model.Menu;
import com.lzyyj.gmis.base.service.IThemeService;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ThemeAction extends ActionSupport {
	
	private IThemeService themeService;
	
	public IThemeService getThemeService() {
		return themeService;
	}

	public void setThemeService(IThemeService menuService) {
		this.themeService = menuService;
	}
	
	private Map<String, Object> mapResult = new HashMap<String, Object>();
	
	public Map<String, Object> getMapResult() {
		return mapResult;
	}

	public void setMapResult(Map<String, Object> mapResult) {
		this.mapResult = mapResult;
	}

	private List<Menu> menus;

	public List<Menu> getMenus() {
		return menus;
	}

	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}
	
	private String mainFrame;
	private String title;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getMainFrame() {
		return mainFrame;
	}

	public void setMainFrame(String mainFrame) {
		this.mainFrame = mainFrame;
	}

	/**
	 * 管理后台首页 index
	 */
	@Override
	public String execute() {
		try {
			getSessionParams();
			
		} catch (Exception e) {
			this.addActionError(e.getMessage());
			return ERROR;
		}
		try {
		} catch (Exception e) {
			this.addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}

	public String top(){
		try {
			getSessionParams();
		} catch (Exception e) {
			this.addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
	
	public String menu(){
		if (themeService==null){
			menus = new ArrayList<Menu>();
			Menu menu = new Menu();
			menu.setName("测试管理");
			menus.add(menu);
			
			Menu subMenu = new Menu();
			subMenu.setName("测试菜单1");
			menu.getMenus().add(subMenu);
			subMenu = new Menu();
			subMenu.setName("测试菜单2");
			menu.getMenus().add(subMenu);
			
			menu = new Menu();
			menu.setName("系统管理");
			menus.add(menu);
			subMenu = new Menu();
			
			subMenu.setName("系统菜单1");
			menu.getMenus().add(subMenu);
			subMenu = new Menu();
			subMenu.setName("系统菜单2");
			menu.getMenus().add(subMenu);
			
		} else {
			try {
				getSessionParams();
			} catch (Exception e) {
				this.addActionError(e.getMessage());
				return ERROR;
			}
		}
		return SUCCESS;
	}

	public String startMainFrame(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			HttpSession session = request.getSession();
			session.setAttribute("mainFrame", mainFrame);
			session.setAttribute("title", title);
			mapResult.put("success", true);
		} catch (Exception e) {
			mapResult.put("success", false);
			mapResult.put("error", e.getMessage());
		}
		return "jsonResult";
	}

	private void getSessionParams() {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		
		mainFrame = (String)session.getAttribute("mainFrame");
		title = (String)session.getAttribute("title");
	}
}